//
//  QcodeViewTool.m
//  OnionHome
//
//  Created by fengjie on 2019/9/25.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "QcodeViewTool.h"

@implementation QcodeViewTool

#pragma mark ---  根据二维码链接创建二维码

+(UIImage *)createQcodeViewUrl:(NSString *)qrcodeUrl{
    //1.二维码滤镜
    CIFilter *filter=[CIFilter filterWithName:@"CIQRCodeGenerator"];
    NSData *data = [qrcodeUrl dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    //2.设置滤镜数据
    [filter setValue:data forKey:@"inputMessage"];
    
    //3.获取滤镜输出的图像
    CIImage *outputImage=[filter outputImage];
    
    //将图放大
    CGAffineTransform transform = CGAffineTransformMakeScale(6, 6); // scale 为放大倍数
    CIImage *transformImage = [outputImage imageByApplyingTransform:transform];
    
    //4.转换成CGImage
    CIContext *context=[CIContext contextWithOptions:nil];
    CGImageRef imageRef = [context createCGImage:transformImage fromRect:transformImage.extent];
    //5.转换成UIImage
    UIImage *qrCodeImage = [UIImage imageWithCGImage:imageRef];
    return qrCodeImage;
}
@end
